package cn.vic.util;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;


public class Sign {


    /**
     * 国大的MD5加密方式
     *
     * @param parameters
     * @param key
     * @param charset
     * @return
     */
    public static String createSign(SortedMap<String, Object> parameters, String key, String charset) {
        StringBuffer sb = new StringBuffer();
        Set es = parameters.entrySet();
        Iterator it = es.iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            String k = (String) entry.getKey();
            String v = (String) entry.getValue();
            if (null != v && !"".equals(v) && !"sign".equals(k)
                    && !"key".equals(k)) {
                sb.append(k + "=" + v + "&");
            }
        }
        sb.append("key=" + key);
        String sign = MD5Util.MD5Encode(sb.toString(), charset).toUpperCase();
        return sign;
    }

}
